package org.zecontech.extraplus.init;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.food.Foods;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.equipment.ArmorMaterial;
import net.minecraft.world.item.equipment.ArmorType;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.zecontech.extraplus.util.Helpers;

import static org.zecontech.extraplus.ExtraPlus.MOD_ID;

// 模组物品
public class ModItems {

    // 模组物品注册总线
    public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID);

    // 生成蛋
    public static final DeferredItem<SpawnEggItem> KELONG =
            registerSpawnEgg("kelong", ModEntities.KELONG);

    // 食物
    public static final DeferredItem<Item> CHENTAO =
            registerFood("chentao", Foods.APPLE);
    public static final DeferredItem<Item> NAILONG_JAR =
            registerFood("nailong_jar", Foods.GOLDEN_APPLE);
    public static final DeferredItem<Item> RUBY_APPLE =
            registerFood("ruby_apple", Foods.GOLDEN_APPLE);
    public static final DeferredItem<Item> COOKED_RUBY_APPLE =
            registerFood("cooked_ruby_apple", Foods.GOLDEN_APPLE);
    public static final DeferredItem<Item> KELONG_MEAT =
            registerFood("kelong_meat", Foods.BEEF);
    public static final DeferredItem<Item> FRIED_EGG =
            registerFood("fried_egg", Foods.BAKED_POTATO);

    // 物品
    public static final DeferredItem<Item> RUBY = registerSimpleItem("ruby");
    public static final DeferredItem<Item> AMBER = registerSimpleItem("amber");
    public static final DeferredItem<Item> SILVER_INGOT = registerSimpleItem("silver_ingot");

    // 武器
    public static final DeferredItem<Item> RUBY_SWORD = registerSword(
            "ruby_sword", ModToolMaterials.RUBY_MATERIAL, 5, -2.4f);
    public static final DeferredItem<Item> SWORD_RED= registerSword(
            "sword_red", ModToolMaterials.RUBY_MATERIAL, 27, -2.0f);
    public static final DeferredItem<Item> AMBER_SWORD = registerSword(
            "amber_sword", ModToolMaterials.AMBER_MATERIAL, 5, -2.4f);
    public static final DeferredItem<Item> EMERALD_SWORD = registerSword(
            "emerald_sword", ModToolMaterials.EMERALD_MATERIAL, 10, -2.4f);
    public static final DeferredItem<Item> SILVER_SWORD = registerSword(
            "silver_sword", ModToolMaterials.SILVER_MATERIAL, 5, -2.4f);

    // 工具
    public static final DeferredItem<Item> RUBY_PICKAXE = registerPickaxe(
            "ruby_pickaxe", ModToolMaterials.RUBY_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> RUBY_AXE = registerAxe(
            "ruby_axe", ModToolMaterials.RUBY_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> RUBY_SHOVEL = registerShovel(
            "ruby_shovel", ModToolMaterials.RUBY_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> RUBY_HOE = registerHoe(
            "ruby_hoe", ModToolMaterials.RUBY_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> AMBER_PICKAXE = registerPickaxe(
            "amber_pickaxe", ModToolMaterials.AMBER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> AMBER_AXE = registerAxe(
            "amber_axe", ModToolMaterials.AMBER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> AMBER_SHOVEL = registerShovel(
            "amber_shovel", ModToolMaterials.AMBER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> AMBER_HOE = registerHoe(
            "amber_hoe", ModToolMaterials.AMBER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> EMERALD_PICKAXE = registerPickaxe(
            "emerald_pickaxe", ModToolMaterials.EMERALD_MATERIAL, 6, -2.8f);
    public static final DeferredItem<Item> EMERALD_AXE = registerAxe(
            "emerald_axe", ModToolMaterials.EMERALD_MATERIAL, 6, -2.8f);
    public static final DeferredItem<Item> EMERALD_SHOVEL = registerShovel(
            "emerald_shovel", ModToolMaterials.EMERALD_MATERIAL, 6, -2.8f);
    public static final DeferredItem<Item> EMERALD_HOE = registerHoe(
            "emerald_hoe", ModToolMaterials.EMERALD_MATERIAL, 6, -2.8f);
    public static final DeferredItem<Item> SILVER_PICKAXE = registerPickaxe(
            "silver_pickaxe", ModToolMaterials.SILVER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> SILVER_AXE = registerAxe(
            "silver_axe", ModToolMaterials.SILVER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> SILVER_SHOVEL = registerShovel(
            "silver_shovel", ModToolMaterials.SILVER_MATERIAL, 3, -2.8f);
    public static final DeferredItem<Item> SILVER_HOE = registerHoe(
            "silver_hoe", ModToolMaterials.SILVER_MATERIAL, 3, -2.8f);

    // 盔甲物品
    public static final DeferredItem<Item> RUBY_HELMET = registerHelmetItem("ruby_helmet", ModArmorMaterials.RUBY_ARMOR);
    public static final DeferredItem<Item> RUBY_CHESTPLATE = registerChestplateItem("ruby_chestplate", ModArmorMaterials.RUBY_ARMOR);
    public static final DeferredItem<Item> RUBY_LEGGINGS = registerLeggingsItem("ruby_leggings", ModArmorMaterials.RUBY_ARMOR);
    public static final DeferredItem<Item> RUBY_BOOTS = registerBootsItem("ruby_boots", ModArmorMaterials.RUBY_ARMOR);
    public static final DeferredItem<Item> RUBY_HORSE_ARMOR = registerHorseArmorItem("ruby_horse_armor", ModArmorMaterials.RUBY_ARMOR);
    public static final DeferredItem<Item> AMBER_HELMET = registerHelmetItem("amber_helmet", ModArmorMaterials.AMBER_ARMOR);
    public static final DeferredItem<Item> AMBER_CHESTPLATE = registerChestplateItem("amber_chestplate", ModArmorMaterials.AMBER_ARMOR);
    public static final DeferredItem<Item> AMBER_LEGGINGS = registerLeggingsItem("amber_leggings", ModArmorMaterials.AMBER_ARMOR);
    public static final DeferredItem<Item> AMBER_BOOTS = registerBootsItem("amber_boots", ModArmorMaterials.AMBER_ARMOR);
    public static final DeferredItem<Item> EMERALD_HELMET = registerHelmetItem("emerald_helmet", ModArmorMaterials.EMERALD_ARMOR);
    public static final DeferredItem<Item> EMERALD_CHESTPLATE = registerChestplateItem("emerald_chestplate", ModArmorMaterials.EMERALD_ARMOR);
    public static final DeferredItem<Item> EMERALD_LEGGINGS = registerLeggingsItem("emerald_leggings", ModArmorMaterials.EMERALD_ARMOR);
    public static final DeferredItem<Item> EMERALD_BOOTS = registerBootsItem("emerald_boots", ModArmorMaterials.EMERALD_ARMOR);
    public static final DeferredItem<Item> SILVER_HELMET = registerHelmetItem("silver_helmet", ModArmorMaterials.SILVER_ARMOR);
    public static final DeferredItem<Item> SILVER_CHESTPLATE = registerChestplateItem("silver_chestplate", ModArmorMaterials.SILVER_ARMOR);
    public static final DeferredItem<Item> SILVER_LEGGINGS = registerLeggingsItem("silver_leggings", ModArmorMaterials.SILVER_ARMOR);
    public static final DeferredItem<Item> SILVER_BOOTS = registerBootsItem("silver_boots", ModArmorMaterials.SILVER_ARMOR);

    /**
     * 注册马甲
     * @param name 马甲名字
     * @param armorMaterial 盔甲材料
     * @return 马甲
     */
    public static DeferredItem<Item> registerHorseArmorItem(String name, ArmorMaterial armorMaterial) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).horseArmor(armorMaterial)));
    }

    /**
     * 注册头盔
     * @param name 头盔名字
     * @param armorMaterial 头盔材料
     * @return 头盔
     */
    public static DeferredItem<Item> registerHelmetItem(String name, ArmorMaterial armorMaterial) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).humanoidArmor(armorMaterial, ArmorType.HELMET)));
    }

    /**
     * 注册胸甲
     * @param name 胸甲名字
     * @param armorMaterial 盔甲材料
     * @return 胸甲
     */
    public static DeferredItem<Item> registerChestplateItem(String name, ArmorMaterial armorMaterial) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).humanoidArmor(armorMaterial, ArmorType.CHESTPLATE)));
    }

    /**
     * 注册护腿
     * @param name 护腿名字
     * @param armorMaterial 盔甲材料
     * @return 护腿
     */
    public static DeferredItem<Item> registerLeggingsItem(String name, ArmorMaterial armorMaterial) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).humanoidArmor(armorMaterial, ArmorType.LEGGINGS)));
    }

    /**
     * 注册靴子
     * @param name 靴子名字
     * @param armorMaterial 盔甲材料
     * @return 靴子
     */
    public static DeferredItem<Item> registerBootsItem(String name, ArmorMaterial armorMaterial) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).humanoidArmor(armorMaterial, ArmorType.BOOTS)));
    }

    /**
     * 注册镐子
     * @param name 物品名字
     * @param toolMaterial 工具材料
     * @param damageAmount 攻击伤害
     * @param attackSpeed 攻击速度
     * @return 镐子
     */
    public static DeferredItem<Item> registerPickaxe(String name, ToolMaterial toolMaterial, float damageAmount, float attackSpeed) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).pickaxe(
                toolMaterial,
                damageAmount,
                attackSpeed
        )));
    }

    /**
     * 注册斧头
     * @param name 物品名字
     * @param toolMaterial 工具材料
     * @param damageAmount 攻击伤害
     * @param attackSpeed 攻击速度
     * @return 斧头
     */
    public static DeferredItem<Item> registerAxe(String name, ToolMaterial toolMaterial, float damageAmount, float attackSpeed) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).axe(
                toolMaterial,
                damageAmount,
                attackSpeed
        )));
    }

    /**
     * 注册铲子
     * @param name 物品名字
     * @param toolMaterial 工具材料
     * @param damageAmount 攻击伤害
     * @param attackSpeed 攻击速度
     * @return 铲子
     */
    public static DeferredItem<Item> registerShovel(String name, ToolMaterial toolMaterial, float damageAmount, float attackSpeed) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).shovel(
                toolMaterial,
                damageAmount,
                attackSpeed
        )));
    }

    /**
     * 注册锄头
     * @param name 物品名字
     * @param toolMaterial 工具材料
     * @param damageAmount 攻击伤害
     * @param attackSpeed 攻击速度
     * @return 锄头
     */
    public static DeferredItem<Item> registerHoe(String name, ToolMaterial toolMaterial, float damageAmount, float attackSpeed) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).hoe(
                toolMaterial,
                damageAmount,
                attackSpeed
        )));
    }

    /**
     * 注册剑
     * @param name 物品名字
     * @param toolMaterial 工具材料
     * @param damageAmount 攻击伤害
     * @param attackSpeed 攻击速度
     * @return 剑
     */
    public static DeferredItem<Item> registerSword(String name, ToolMaterial toolMaterial, float damageAmount, float attackSpeed) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).sword(
                toolMaterial,
                damageAmount,
                attackSpeed
        )));
    }

    /**
     * 注册生物生成蛋
     * @param name 物品名字
     * @param entityType 实体类型
     * @return 生物生成蛋
     * @param <E> 继承自Mob的生物
     */
    public static <E extends Mob> DeferredItem<SpawnEggItem> registerSpawnEgg(String name, DeferredHolder<EntityType<? extends Entity>, EntityType<E>> entityType) {
        return ITEMS.registerItem(name,
                properties -> new SpawnEggItem(
                        entityType.get(),
                        properties
                ));
    }

    /**
     * 注册食物
     * @param name 名字
     * @param foodProperties 食物属性
     * @return 食物
     */
    public static DeferredItem<Item> registerFood(String name, FoodProperties foodProperties) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name)).food(foodProperties)));
    }

    /**
     * 注册简单物品
     * @param name 物品名字
     * @return 简单物品
     */
    public static DeferredItem<Item> registerSimpleItem(String name) {
        return ITEMS.registerItem(name, item -> new Item(item.setId(Helpers.createKey(Registries.ITEM, name))));
    }
}